package com.tyrone.gateway.route;

import com.tyrone.gateway.route.bean.RouteInfo;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
public class RouterManager {
    // TODO: 2024/4/9 store 路由缓存相关的操作后续再写
    private static List<RouteInfo> store = new ArrayList<>();

    public RouteInfo getRouteInfoByRawPath(String rawPath) {
        assert rawPath != null;
        List<RouteInfo> routeInfos = store.stream().filter(routeInfo -> StringUtils.equals(rawPath, routeInfo.getRawPath()))
//                .sorted(Comparator.comparingInt(RouteInfo::getOrder).reversed())
                .collect(Collectors.toList());
        return !routeInfos.isEmpty() ? routeInfos.get(0) : null;
    }

}
